function [x,fval,residual,exitflag,output]=optim_fitsurface(Param,xdata,ydata,yerr,LB,UB)
options=optimset('MaxIter',500,'TolFun',1e-8,'Display','iter','TolX',1e-8,'MaxFunEvals',2000);
[x,fval,residual,exitflag,output]=lsqcurvefit(@nestedfun,Param,xdata,(ydata./yerr),LB,UB,options);
    function y=nestedfun(Param,xdata)
        C=Param(1);
        qc=Param(2);
        Z=Param(3);
        
        qz=xdata;
       Eng=8.05;
       lambda=1.54;
       Attl=1008e4; % Attenuation length in unit of Angstrom for water @ 13.474 keV
       mu=1/Attl;
       beta=mu*lambda/4/pi;
  
        
        D=fitsubphase(qz,qc,Eng,Attl);
        y=C*Transmission(qz,qc,beta,lambda).*exp(-Z./D);
        y=(y./yerr);
    end
end